import React, { Component } from 'react'
import { CountConsumer } from './CounterContext'

export default class CountButton extends Component {
  render() {
    let txt = this.props.type === 'increment' ? '+' : '-'
    return (
      <CountConsumer>
        {
          ({inc,dec}) => {
            let handleClick= this.props.type === 'increment' ? inc : dec
            return (
              <button onClick={handleClick}>
                {txt}
              </button>
            )
          }
        }
      </CountConsumer>

    )
  }
}
